﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using YY.DataLinq;
using System.Data;

namespace YY.WCFLib
{
    // 注意: 如果更改此处的接口名称 "IBaseData"，也必须更新 App.config 中对 "IBaseData" 的引用。
    [ServiceContract]
    public interface IBaseData
    {
        #region 获取流水号
        /// <summary>
        /// 获取流水号（单据、其它类）
        /// </summary>
        /// <param name="type">1-单据,2-其它类</param>
        /// <param name="billType">单据类型</param>
        /// <param name="len">自定义流水号长度</param>
        /// <param name="prefix">是否加前缀</param>
        /// <param name="fillZero">是否补零</param>
        /// <returns>流水号</returns>
        [OperationContract]
        string GetSerialNo(int type, string billType, int len, bool prefix, bool fillZero, bool fillDate);
        #endregion

        #region 用户
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="code"></param>
        /// <param name="pwd"></param>
        /// <returns>错误消息</returns>
        [OperationContract]
        LoginResult CheckLogin(string code, string pwd);

        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [OperationContract]
        int AddUser(TB_User obj);

        /// <summary>
        /// 修改用户资料
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [OperationContract]
        bool UpdateUser(TB_User obj);

        /// <summary>
        /// 删除用户资料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        bool DeleteUser(int id);

        /// <summary>
        /// 获取单个用户资料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        TB_User GetUser(int id);

        /// <summary>
        /// 搜索用户资料
        /// </summary>
        /// <param name="code"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        [OperationContract]
        IEnumerable<TB_User> FindUsers(string code, string userName);

        /// <summary>
        /// 检查用户账号是否重复
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [OperationContract]
        bool ExistUserCode(string code);
        #endregion

        #region 客户
        [OperationContract]
        int AddClient(TB_Clients obj);

        [OperationContract]
        bool UpdateClient(TB_Clients obj);

        [OperationContract]
        bool DeleteClient(int id);

        [OperationContract]
        TB_Clients GetClient(int id);

        [OperationContract]
        IEnumerable<TB_Clients> FindClients(string shortName, string name, string tel, string address, string contactMan);
        #endregion

        #region 通用分类管理

        /// <summary>
        /// 获取单个分类信息
        /// </summary>
        /// <param name="id">分类系统编号</param>
        /// <returns>分类对象</returns>
        [OperationContract]
        TB_Options GetOption(int id);


        /// <summary>
        /// 获取单个分类信息
        /// </summary>
        /// <param name="type">分类类型</param>
        /// <param name="name">分类名称</param>
        /// <returns>分类对象</returns>
        [OperationContract]
        TB_Options GetOptionByTpNm(string type, string name);


        /// <summary>
        /// 获取分类树形关系
        /// </summary>        
        /// <param name="type">分类类型</param>
        /// <returns>TB_Options</returns>      
        [OperationContract]
        IEnumerable<TB_Options> GetOptionTree(string type);

        /// <summary>
        /// 查找分类
        /// </summary>
        /// <param name="type">分类类型</param>
        /// <param name="code">分类代号</param>
        /// <param name="name">分类名称</param>
        /// <returns>TB_Options</returns>
        [OperationContract]
        IEnumerable<TB_Options> FindOptions(string type, string code, string name);


        /// <summary>
        /// 新增分类
        /// </summary>
        /// <param name="option">分类</param>
        /// <returns>新建分类系统编号</returns>
        [OperationContract]
        int AddOption(TB_Options option);


        /// <summary>
        /// 更新一个分类
        /// </summary>
        /// <param name="option">分类类</param>
        /// <returns>是否更新成功</returns>
        [OperationContract]
        bool UpdateOption(TB_Options option);


        /// <summary>
        /// 删除一个分类
        /// </summary>
        /// <param name="id">分类系统编号</param>
        /// <returns>是否删除成功</returns>
        [OperationContract]
        bool DeleteOption(int id);
        #endregion

        #region 工作单
        [OperationContract]
        int AddOrder(TB_Order obj);
        [OperationContract]
        bool UpdateOrder(TB_Order obj);
        [OperationContract]
        MsgBoolean DeleteOrder(int id);
        [OperationContract]
        TB_Order GetOrder(int id);

        [OperationContract]
        TB_Order GetOrderByCode(string code);

        [OperationContract]
        IEnumerable<QOrder> FindOrders(bool? deleteFlag, string orderCode, string cCode, DateTime? sDate, DateTime? eDate, string orderStatus, int? agent, int? bizMan, int? stowageMethod, string clientName, bool? isDrawback, string customsStatus, string checkOffCode, string caseCode);

        [OperationContract]
        IEnumerable<QOrder> FindOrders2(bool? deleteFlag, string orderCode, string cCode, DateTime? sDate, DateTime? eDate,
            string orderStatus, int? agent, int? bizMan, int? stowageMethod, string clientName, bool? isDrawback,
            string customsStatus, string checkOffCode, string caseCode, int loginUserId, int loginUserRole, int pageSize, int pageIndex, out int recordCount, out int pageCount);

        [OperationContract]
        DataTable GetOrderBill(int targetId, DateTime sDate, DateTime eDate, int feeType);
        #endregion

        #region 工作流
        [OperationContract]
        int AddWorkflow(TB_Workflow obj);

        [OperationContract]
        MsgBoolean HandleWorkflow(int orderId, int opType, int? nextOp, string nextOpStatus, string comment);
        [OperationContract]
        MsgBoolean HandleWorkflow2(int orderId, int opType, int? nextOp, string nextOpStatus, string comment, int loginUserId, int loginUserRole);

        [OperationContract]
        TB_Workflow GetCurrentWorkflow(TB_Order order);

        [OperationContract]
        IEnumerable<QWorkflow> FindWorkflow(int orderId);
        #endregion

        #region 拖车信息
        [OperationContract]
        bool UpdateTrailer(int orderId, IEnumerable<TB_Trailer> objs);
        [OperationContract]
        TB_Trailer GetTrailer(int id);
        #endregion

        #region 报关信息
        [OperationContract]
        bool UpdateCustoms(int orderId, IEnumerable<TB_Customs> objs);
        [OperationContract]
        TB_Customs GetCustoms(int id);

        [OperationContract]
        TB_Customs GetCustomsByOrderId(int orderId);

        [OperationContract]
        IEnumerable<TB_CheckOff> GetCheckOffs(int id);

        /// <summary>
        /// 通过申报日期段获取核销单
        /// </summary>
        /// <param name="sDate"></param>
        /// <param name="eDate"></param>
        /// <returns></returns>
        [OperationContract]
        List<QCheckOrder> GetCheckOffsByApplyDate(DateTime sDate, DateTime eDate);
        #endregion

        #region 货物信息
        [OperationContract]
        int AddCase(TB_Case obj);
        [OperationContract]
        bool UpdateCase(TB_Case obj);
        [OperationContract]
        bool DeleteCase(int id);
        [OperationContract]
        TB_Case GetCase(int id);
        [OperationContract]
        IEnumerable<TB_Case> GetCases(int id);

        [OperationContract]
        int AddCargo(TB_Cargo obj);
        [OperationContract]
        bool UpdateCargo(TB_Cargo obj);
        [OperationContract]
        bool DeleteCargo(int id);
        [OperationContract]
        TB_Cargo GetCargo(int id);
        [OperationContract]
        IEnumerable<XCargo> GetXCargos(int id);

        [OperationContract]
        IEnumerable<TB_Cargo> GetCargos(int id);
        [OperationContract]
        bool UpdateCases(int orderId, IEnumerable<TB_Case> objs);
        #endregion

        #region 附件信息
        [OperationContract]
        int AddAttach(TB_Attach obj);
        [OperationContract]
        bool DeleteAttach(int id);

        [OperationContract]
        TB_Attach GetAttach(int id);

        [OperationContract]
        IEnumerable<TB_Attach> GetAttachs(int id);

        [OperationContract]
        TransferFileInfo UploadAttach(TransferFileInfo file);

        /// <summary>
        /// 根据文件名寻找文件是否存在
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        RemoteFileInfo DownloadAttach(DownloadRequest request);
        #endregion

        #region 费用信息
        [OperationContract]
        int AddFee(TB_Fee obj);

        [OperationContract]
        bool UpdateFee(TB_Fee obj);

        [OperationContract]
        bool DeleteFee(int id);

        [OperationContract]
        TB_Fee GetFee(int id);

        [OperationContract]
        IEnumerable<TB_Fee> GetFees(int id);
        [OperationContract]
        IEnumerable<XFee> GetXFees(int id);

        [OperationContract]
        bool UpdateFees(int orderId, IEnumerable<TB_Fee> objs);

        [OperationContract]
        IEnumerable<QFee> FindFees(string orderCode, string orderStatus, int? bizMan, int? op, DateTime? sDate, DateTime? eDate, int? feeType, string feeCode, int? item, int? target, bool? isVerify);

        [OperationContract]
        IEnumerable<QFee> FindFees2(string orderCode, string orderStatus, int? bizMan, int? op, DateTime? sDate, DateTime? eDate, int? feeType, string feeCode, int? item, int? target, bool? isVerify,
            int loginUserId, int loginUserRole, int pageSize, int pageIndex, out int recordCount, out int pageCount);

        #endregion

        #region 收支信息

        [OperationContract]
        int AddBalance(TB_Balance obj);

        [OperationContract]
        bool UpdateBalance(TB_Balance obj);

        [OperationContract]
        bool DeleteBalance(int id);

        [OperationContract]
        TB_Balance GetBalance(int id);

        [OperationContract]
        IEnumerable<TB_Balance> FindBalances(DateTime? sDate, DateTime? eDate, int? target, int? balanceType, string bank, string keyWord);

        [OperationContract]
        IEnumerable<TB_Balance> FindBalances2(DateTime? sDate, DateTime? eDate, int? target, int? balanceType, string bank, int loginUserId, int loginUserRole, int pageSize, int pageIndex, out int recordCount, out int pageCount);
        #endregion

        #region 权限
        /// <summary>
        /// 查找系统模块
        /// </summary>
        /// <param name="frmId"></param>
        /// <param name="frmParams"></param>
        /// <returns></returns>
        [OperationContract]
        IEnumerable<TB_SysModule> FindSysModules(string frmId, string[] frmParams);

        /// <summary>
        /// 根据特定条件查找用户操作权限
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="moduleId"></param>
        /// <param name="frmId"></param>
        /// <returns></returns>
        [OperationContract]
        IEnumerable<TB_ActionPermission> FindActionPermissions(bool? isRole, int? ownerId, int? moduleId, string frmId);

        /// <summary>
        /// 更新用户操作权限
        /// </summary>
        /// <param name="objs"></param>
        /// <returns></returns>
        [OperationContract]
        bool UpdateActionPermission(int ownerId, int moduleId, TB_ActionPermission[] objs);

        /// <summary>
        /// 查找角色模块关系
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        [OperationContract]
        IEnumerable<TB_RoleModule> FindRoleModules(int? roleId);

        /// <summary>
        /// 更新角色模块关系
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="modules"></param>
        /// <returns></returns>
        [OperationContract]
        bool UpdateRoleModule(int roleId, IEnumerable<TB_RoleModule> objs);
        #endregion

        #region 汇总统计
        [OperationContract]
        DataTable GetCountFee(DateTime sDate, DateTime eDate, int? bizMan);
        [OperationContract]
        DataTable GetCountFee2(DateTime sDate, DateTime eDate, int? bizMan, int loginUserId, int loginUserRole);
        #endregion

        #region 菜单
        [OperationContract]
        IEnumerable<TB_SysModule> GetUserMenus();

        [OperationContract]
        IEnumerable<TB_SysModule> GetUserMenus2(int role, string frmId);
        #endregion

        #region 系统参数配置
        /// <summary>
        /// 获取系统参数配置
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        IEnumerable<TB_SysParams> GetSysParams();
        #endregion
    }
}
